import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:myflutterproject/basematerialwidgetsdemo.dart';
import 'package:myflutterproject/utils/overScrollBehavior.dart';
/*待补充*/
class Flowdemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Flow'),
        centerTitle: true,
      ),
      body: FlowPage()/*ScrollConfiguration(
        behavior: OverScrollBehavior(),
        *//*使用了ListView子控件width不起效  换成Wrap*//*
        child: Column(
          children: <Widget>[
            TextWidget('基础Flow:'),
            FlowNormalDemo(),

          ],
        ),
      // ),
    ),*/
    );
  }

}
class FlowPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: 200,
      height: 200,
      color: Colors.grey.withAlpha(66),
      alignment: Alignment.center,
      child: FlowNormalDemo(),
    );
  }
}

class FlowNormalDemo extends StatelessWidget {
  final sides = [60.0, 50.0, 40.0, 30.0];
  final colors = [Colors.red, Colors.yellow, Colors.blue, Colors.green];

  @override
  Widget build(BuildContext context) {
    return Flow(
        delegate:_FlowNormalDelegate(),
        children: sides.map((e) => _buildItem(e)).toList(),
    );
  }

  Widget _buildItem(double e) {
    return Container(
      width: e,
      alignment: Alignment.center,
      height: e,
      color: colors[sides.indexOf(e)],
      child: Text('$e'),
    );
  }
}

class _FlowNormalDelegate extends FlowDelegate {
  //画孩子
  @override
  void paintChildren(FlowPaintingContext context) {
    print('父容器尺寸：${context.size}');
    print('孩子的个数：${context.childCount}');
    for(int i=0;i<context.childCount;i++){
      print('第$i个孩子尺寸：${context.getChildSize(i)}');
      //绘制孩子
      context.paintChild(i);
    }

  }

  //绘制的上下文，即绘制的信息
  @override
  bool shouldRepaint(covariant FlowDelegate oldDelegate) {
    return true;
  }

}